fix(web): render Mermaid diagrams in Markdown - #6191
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This PR adds a production Mermaid dependency and changes the default rendering of completed Mermaid fences across the shared web Markdown renderer, including SVG injection and clipboard behavior. The new user-facing capability and security-sensitive rendering surface exceed a small isolated fix and warrant human review. You can add or adjust custom eligibility rules. Learn more. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4653760dcf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Would really like to see mermaid support land in some form. Agents lean on it heavily for architecture and flow diagrams, and today those blocks are just walls of source in the chat. @t3dotgg @juliusmarminge this one and #8533 both tackle it. Could one of you pick a direction so the work isn't stuck? |
fa0583d to
120a102
Compare
120a102 to
38e6fa6
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 38e6fa6. Configure here.

Mermaid fences currently render as ordinary code blocks in T3 Code, so diagrams in Markdown lose the visual structure available in renderers that support Mermaid.
This change lazy-loads Mermaid when a completed Mermaid fence is present, serializes rendering because Mermaid configuration is global, and falls back to the original fenced code if rendering fails. Diagrams use strict security mode, follow the active theme, retain readable intrinsic sizing, and preserve their original Markdown for copy operations.
The shared web Markdown renderer covers chat, timelines, plans, Markdown file previews, and pull request bodies and reviews. Desktop inherits the web behavior; mobile remains unchanged because it uses a separate native renderer.
Validation
vp test run apps/web/src/components/MermaidDiagram.test.tsvp lint apps/web/src/components/MermaidDiagram.tsx apps/web/src/components/MermaidDiagram.test.ts apps/web/src/components/ChatMarkdown.tsx apps/web/src/markdown-clipboard.tsvp run --filter @t3tools/web typecheckvp run --filter @t3tools/web buildModel: GPT-5.6 Codex in T3 Code.
Note
Add Mermaid diagram rendering to
ChatMarkdownChatMarkdownrenders completedmermaidfenced blocks through the newMermaidDiagramcomponent instead of source code. Streaming blocks and failed renders fall back to Shiki.MermaidDiagramdynamically loads Mermaid, initializes with strict security and the active theme, and injects the SVG into a scrollable container.data-markdown-copywhen copying a rendered diagram.data-markdown-copyancestor copy explicit Markdown text instead of the rendered fragment. Streamingmermaidblocks render via Shiki.Macroscope summarized cf50ae5.
Note
Medium Risk
Introduces client-side diagram rendering with injected SVG HTML in chat markdown; mitigated by Mermaid strict security, render fallbacks, and bounded copy serialization, but still expands untrusted-content parsing surface and bundle weight.
Overview
Chat markdown now renders completed
mermaidfenced blocks as diagrams instead of Shiki code, while streaming messages still show the normal code path until the fence is finished.A new
MermaidDiagrampath lazy-loads mermaid, runs renders on a global serial queue (because Mermaid config is shared), uses strict security settings and the active light/dark theme, and falls back to the existing highlighted code block on failure or while loading. Diagram containers get scroll-friendly layout CSS and the code-block wrap control is hidden when diagram output is shown.Copy/paste is updated so rendered diagrams expose
data-markdown-copywith a safely length-padded fence viaserializeMarkdownCodeFence, and clipboard handling prefers that ancestor markdown when a selection only captures inner SVG text.Reviewed by Cursor Bugbot for commit cf50ae5. Bugbot is set up for automated code reviews on this repo. Configure here.